package follow.juc.writing.demo1;

import java.util.concurrent.*;

/**
 * @author tu zy
 * @version 1.0
 * @date 2020/11/28 18:22
 */

public class ThreedPoolDemo implements Runnable{

    @Override
    public void run() {
        System.out.println("我是实现runnable接口然后使用线程池实现多线程");
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        FutureTask<String> task = new FutureTask<>(new ThreadDemo());
        //executorService.execute(new ThreedPoolDemo());
        try {
            executorService.execute(task);
            String s = task.get();
            System.out.println(s);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        executorService.shutdown();

    }
    static class ThreadDemo implements Callable<String>{
        @Override
        public String call() throws Exception {
            return "我是首先实现Callable方法的多线程";
        }
    }
}
